<?php
namespace Wechat\Model\Table;

use Cake\ORM\Query;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;

/**
 * Wechats Model
 *
 * @method \Wechat\Model\Entity\Wechat get($primaryKey, $options = [])
 * @method \Wechat\Model\Entity\Wechat newEntity($data = null, array $options = [])
 * @method \Wechat\Model\Entity\Wechat[] newEntities(array $data, array $options = [])
 * @method \Wechat\Model\Entity\Wechat|bool save(\Cake\Datasource\EntityInterface $entity, $options = [])
 * @method \Wechat\Model\Entity\Wechat patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
 * @method \Wechat\Model\Entity\Wechat[] patchEntities($entities, array $data, array $options = [])
 * @method \Wechat\Model\Entity\Wechat findOrCreate($search, callable $callback = null, $options = [])
 */
class WechatsTable extends Table
{

    /**
     * Initialize method
     *
     * @param array $config The configuration for the Table.
     * @return void
     */
    public function initialize(array $config)
    {
        parent::initialize($config);

        $this->setTable('wechats');
        $this->setDisplayField('id');
        $this->setPrimaryKey('id');
    }

    /**
     * Default validation rules.
     *
     * @param \Cake\Validation\Validator $validator Validator instance.
     * @return \Cake\Validation\Validator
     */
    public function validationDefault(Validator $validator)
    {
        $validator
            ->integer('id')
            ->allowEmpty('id', 'create');

        $validator
            ->scalar('appId')
            ->maxLength('appId', 30)
            ->allowEmpty('appId');

        $validator
            ->scalar('secret')
            ->maxLength('secret', 36)
            ->allowEmpty('secret');

        $validator
            ->scalar('token')
            ->maxLength('token', 32)
            ->allowEmpty('token');

        $validator
            ->scalar('aesKey')
            ->maxLength('aesKey', 43)
            ->allowEmpty('aesKey');

        $validator
            ->scalar('oauthScopes')
            ->maxLength('oauthScopes', 20)
            ->allowEmpty('oauthScopes');

        return $validator;
    }
}
